﻿@page
@model Logger7.Pages.Logger.ListModel
@{
    ViewData["Title"] = "日志列表";
}
@* <nav class="navbar navbar-expand-lg bg-body-tertiary navbar-dark fixed-top"> *@

<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-dark border-bottom box-shadow mb-3 fixed-top">

    <div class="container-fluid">
        <a class="navbar-brand" href="@TempData.Peek("RUrl")">返回</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                <li class="nav-item">
                    <a class="nav-link" href="#" onclick="SetPage(-1)">前一页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#" onclick="SetPage(1)">后一页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#" onclick="SetPage(-2)">删除一月前日志</a>
                </li>
            </ul>
            <form class="d-flex" role="search" id="Form1">
                <input class="form-control me-1" type="search" style="width:80px" placeholder="页号" aria-label="Search" asp-for="PageNo">
                <input class="form-control me-1" type="search" style="width:80px" placeholder="数量" aria-label="Search" asp-for="PageSize">
                <input class="form-control me-1" type="search" placeholder="类别" aria-label="Search" asp-for="CategoryName">
                <input class="form-control me-1" type="search" placeholder="关键字" aria-label="Search" asp-for="SearchText">
                <input class="btn btn-outline-success" type="submit" value="查 询" />
            </form>
        </div>
    </div>
</nav>

<table class="table table-striped table-sm table-hover" style="margin-top:70px">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Items[0].Id)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Items[0].Dt)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Items[0].LogLevel)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Items[0].UserExt)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Items[0].Name)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Items[0].Msg)
            </th>
            @*             <th style="word-break:break-all; word-wrap:break-all;">
            @Html.DisplayNameFor(model => model.Items[0].Exception)
            </th>
            *@
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model.Items)
        {
            string trclass;
            switch (item.LogLevel)
            {
                case LogLevel.Error:
                    trclass = "table-danger";
                    break;
                case LogLevel.Warning:
                    trclass = "table-warning";
                    break;
                default:
                    trclass = "table-info";
                    break;
            }

            <tr class="@trclass">
                <td> <a asp-page="./Details" asp-route-id="@item.Id">@item.Id</a></td>
                <td>@item.Dt.ToString("yy/MM/dd HH:mm:ss.fff")</td>
                <td>@item.LogLevel</td>
                <td>@item.UserExt</td>
                <td onclick="SetSearch('@item.Name')">@item.Name</td>
                <td style="word-break:break-all; word-wrap:break-all;"><brs>@item.Msg</brs><br /><brs>@item.Exception</brs></td>
            </tr>

        }
    </tbody>
</table>

@section scripts
{
    <script>
        $(function () {

            if ("@ViewData["Count"]" != "") {

                $("#PageNo").val(0);
                alert("删除了" + '@ViewData["Count"]' + " 条记录");
            }

            $("#PageNo").change(function () {
                $("#Form1").submit();
            });
            $("#PageSize").change(function () {
                $("#Form1").submit();
            });

        });
        function SetPage(count) {
            if (count == -2) {
                $("#PageNo").val(-1);
                $("#Form1").submit();
            }
            var pageNo = $("#PageNo").val() * 1 + count;
            if (pageNo < 0)
                return;
            $("#PageNo").val(pageNo);
            $("#Form1").submit();
        }
        function SetSearch(searchText) {
            $("#CategoryName").val(searchText);
        }
    </script>
}
